package org.budo.druid.filter.statement.error;

import java.sql.SQLException;

import org.budo.druid.proxy.util.PreparedStatementProxyUtil;

import com.alibaba.druid.filter.FilterAdapter;
import com.alibaba.druid.filter.FilterChain;
import com.alibaba.druid.proxy.jdbc.PreparedStatementProxy;
import com.alibaba.druid.proxy.jdbc.ResultSetProxy;

/**
 * @author li
 * @version 1 (2015年1月5日 下午4:43:08)
 * @since Java7
 */
public class PreparedStatementExecuteErrorFilter extends FilterAdapter {
    public ResultSetProxy preparedStatement_executeQuery(FilterChain chain, PreparedStatementProxy preparedStatementProxy) throws SQLException {
        try {
            return super.preparedStatement_executeQuery(chain, preparedStatementProxy);
        } catch (SQLException e) {
            throw new SQLException("sql=" + PreparedStatementProxyUtil.getExecutableSql(preparedStatementProxy), e);
        }
    }

    public int preparedStatement_executeUpdate(FilterChain chain, PreparedStatementProxy preparedStatementProxy) throws SQLException {
        try {
            return super.preparedStatement_executeUpdate(chain, preparedStatementProxy);
        } catch (SQLException e) {
            throw new SQLException("sql=" + PreparedStatementProxyUtil.getExecutableSql(preparedStatementProxy) + ", e=" + e, e);
        }
    }

    public int resultSet_getInt(FilterChain chain, ResultSetProxy result, int columnIndex) throws SQLException {
        return super.resultSet_getInt(chain, result, columnIndex);
    }

    public int resultSet_getInt(FilterChain chain, ResultSetProxy result, String columnLabel) throws SQLException {
        return super.resultSet_getInt(chain, result, columnLabel);
    }
}